#   库的引用
import os.path

import PyQt6.QtWidgets as QtWidgets
import PyQt6.QtGui as QtGui

#   任务管理
class Tasks(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()
        self.basePath = os.path.dirname(os.path.abspath(__file__))
        self.initUI()

    def initUI(self):
        #   设置主题
        self.stylePath = os.path.join(self.basePath, "Qss/tasks.qss")
        self.qssFile = open(self.stylePath, 'r')
        self.qssStyle = self.qssFile.read()
        self.setStyleSheet(self.qssStyle)

        #   主Layout
        self.vbox = QtWidgets.QVBoxLayout()
        self.vbox.setContentsMargins(0, 0, 0, 0)
        self.vbox.setSpacing(6)
        self.setLayout(self.vbox)

        #   事件列表
        self.tasksList = QtWidgets.QListWidget()
        self.vbox.addWidget(self.tasksList)

        #   控制区域
        self.ctrlWidget = QtWidgets.QWidget()
        self.vbox.addWidget(self.ctrlWidget)
        self.ctrlLayout = QtWidgets.QHBoxLayout()
        self.ctrlLayout.setContentsMargins(0, 0, 0, 0)
        self.ctrlLayout.setSpacing(6)
        self.ctrlWidget.setLayout(self.ctrlLayout)

        self.labInfo = QtWidgets.QLabel("已加载0项任务")
        self.ctrlLayout.addWidget(self.labInfo)
        self.ctrlLayout.addStretch(1)

        self.btnDel = QtWidgets.QPushButton("删除")
        self.iconPath = os.path.join(self.basePath, "Icon/del.png")
        self.btnDel.setIcon(QtGui.QIcon(self.iconPath))
        self.ctrlLayout.addWidget(self.btnDel)

        self.btnDetail = QtWidgets.QPushButton("详情")
        self.iconPath = os.path.join(self.basePath, "Icon/detail.png")
        self.btnDetail.setIcon(QtGui.QIcon(self.iconPath))
        self.ctrlLayout.addWidget(self.btnDetail)